package com.zero.yygh.cmn.listener;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zero.yygh.cmn.mapper.DictMapper;
import com.zero.yygh.model.cmn.Dict;
import com.zero.yygh.vo.cmn.DictEeVo;

/**
 * @author zero
 * @desc excel处理监听
 * @create 2021/3/24
 */
public class DictExcelListener extends AnalysisEventListener<DictEeVo> {

    private final DictMapper dictMapper;

    public DictExcelListener(DictMapper dictMapper){
        this.dictMapper = dictMapper;
    }

    /**
     * 按行读取处理文件
     * @param dictEeVo 每行数据
     * @param context 数据上下文
     */
    @Override
    public void invoke (DictEeVo dictEeVo, AnalysisContext context) {
        Dict dict = new Dict();
        BeanUtil.copyProperties(dictEeVo, dict);
        dictMapper.insert(dict);
    }

    /**
     * if have something to do after all analysis
     * @param context
     */
    @Override
    public void doAfterAllAnalysed (AnalysisContext context) {

    }
}
